import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:convert';

part 'position_response.freezed.dart';
part 'position_response.g.dart';

@freezed
class PositionResponse with _$PositionResponse {
  const factory PositionResponse({
    @JsonKey(name: "c") required int c,
    @JsonKey(name: "m") required String m,
    @JsonKey(name: "d") required List<D> d,
  }) = _PositionResponse;

  factory PositionResponse.fromJson(Map<String, dynamic> json) =>
      _$PositionResponseFromJson(json);
}

@freezed
class D with _$D {
  const factory D({
    @JsonKey(name: "id") required String id,
    @JsonKey(name: "mode") required int mode,
    @JsonKey(name: "title") required String title,
    @JsonKey(name: "description") required String description,
    @JsonKey(name: "style") required dynamic style,
    @JsonKey(name: "author") required String? author,
    @JsonKey(name: "source") required String source,
    @JsonKey(name: "comment_count") required String commentCount,
    @JsonKey(name: "thumb") required String thumb,
    @JsonKey(name: "images") required List<Image>? images,
    @JsonKey(name: "time") required String time,
    @JsonKey(name: "sort") required String sort,
    @JsonKey(name: "url") required String url,
  }) = _D;

  factory D.fromJson(Map<String, dynamic> json) => _$DFromJson(json);
}

@freezed
class Image with _$Image {
  const factory Image({
    @JsonKey(name: "url") required String url,
    @JsonKey(name: "desc") required String desc,
  }) = _Image;

  factory Image.fromJson(Map<String, dynamic> json) => _$ImageFromJson(json);
}
